package com.kinyx.framework.log;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.lookup.MainMapLookup;

/**
 * 日志工厂（log4j2实现类）
 */
public final class LogFactory4Log4j2 extends LogFactory<Log4log4j2> {

	@Override
	void initialize() {
		MainMapLookup.setMainArguments("log_tag", Configs.logTag);
	}

	@Override
	void setLevel(final String packageName, final LogLevel level) {
		Configurator.setLevel(packageName, this.convert(level));
	}

	@Override
	void setRootLevel(final LogLevel level) {
		Configurator.setRootLevel(this.convert(level));
	}

	private Level convert(final LogLevel level) {
		switch (level) {
			case trace:
				return Level.TRACE;
			case debug:
				return Level.DEBUG;
			case info:
				return Level.INFO;
			case warn:
				return Level.WARN;
			case error:
				return Level.ERROR;
			case fatal:
				return Level.FATAL;
		}
		return null;
	}

}
